/**
 * <p>Title: EngineeringDesign.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-2-18 上午10:22:58  张志芳  Create
 *</pre>
 */
package com.baosight.sczx.common.zm.cInterface.cs;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.iplat4j.ef.ui.tree.TreeConstants;

/**
 * <p>Title: EngineeringDesign.java</p>
 * <p>Description: 工程设计的接口类</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-2-18 上午10:22:58  张志芳  Create
 *</pre>
 */
public class EngineeringDesign {

	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 工程建模中获取工程设计树节点
	 * <p>Function: getEngineeringDesignTreeByMineId</p>
	 * <p>Description: </p>
	 * <p>return value:List<String></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-10上午07:19:17 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes" })
	public static List getEngineeringModelTreeByMineId(String mineId) {
		List  _list = new ArrayList();
		try {
			Map<String, String> params = new HashMap<String, String>();
			params.put("fdMineId", mineId);
			_list = dao.query("ZMCSEngineeringDesign.queryTree", params);
		} catch (Exception e) {

		}
		return _list;
	}
	
	/**
	 * 根据工程设计ID获取矿井编号
	 * <p>Function: getFdMineNoByFdKeyId</p>
	 * <p>Description: </p>
	 * <p>return value:String</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13上午07:20:28 严洪浩
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static String getFdMineNoByFdKeyId(String fdKeyId) {
		Map<String, String> _map = new HashMap<String, String>();
		_map.put("fdKeyId", fdKeyId);
		
		List<Map>  _list = new ArrayList<Map>();
		try {
			_list = dao.query("ZMCSEngineeringDesign.queryMineNumber", _map, 0, 1);
			Map _resukt = _list.get(0);
			String fdNo = _resukt.get("fdNo") == null ? "" : (String)_resukt.get("fdNo");
			return fdNo;
		} catch (Exception e) {
			
		}
		return "";
	}
	
	/**
	 * 根据矿井ID获取所有的工作面、巷道、其他设计ID
	 * For工程查询
	 * <p>Function: getMineDesign</p>
	 * <p>Description: </p>
	 * <p>return value:List<ZM02></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-18下午05:02:39 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static List<String> getMineDesign(String mineId){
		List<String> _result = new ArrayList();
		try {
			List<Map>  _list = new ArrayList();
			Map param = new HashMap();
			param.put("fdMineId", mineId);
			
			_list = dao.query("ZMCSWorkingFace.queryInterfaceByMine", param);
			for(int i = 0; i < _list.size(); i++)
			{
				_result.add(_list.get(i).get("fdParentId").toString());
			}
			
			_list = dao.query("ZMCSRoadWay.queryInterfaceByMine", param);
			for(int i = 0; i < _list.size(); i++)
			{
				_result.add(_list.get(i).get("fdParentId").toString());
			}
			
			_list = dao.query("ZMCSOtherDesign.queryInterfaceByMine", param);
			for(int i = 0; i < _list.size(); i++)
			{
				_result.add(_list.get(i).get("fdParentId").toString());
			}		
		} catch (Exception e) {

		}
		return _result;
	}
	
	/**
	 * 根据类型获取工程设计的ID
	 * For工程查询
	 * <p>Function: getTypeDesign</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-2-18上午10:39:56 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static List<String> getTypeDesign(String type, String designId){                                                              
		List<String>  allList = new ArrayList();
		try {
			List<Map>  _list = new ArrayList();
			Map param = new HashMap();
			param.put("fdEngineeringDesignId", designId);
			if(type == null || type.equals("")) {
				return allList;
			}
			if("1".equals(type)){
				_list = dao.query("ZMCSWorkingFace.queryInterfaceByDesign", param);
			}
			else if("2".equals(type)){
				_list = dao.query("ZMCSRoadWay.queryInterfaceByDesign", param);
			}
			else if("3".equals(type)){
				_list = dao.query("ZMCSOtherDesign.queryInterfaceByDesign", param);
			}
			for(int i=0;i<_list.size();i++)
			{
				allList.add(_list.get(i).get("fdParentId").toString());
			}
		} catch (Exception e) {
			System.out.println("根据类型获取工程设计的ID异常: " + e.getMessage());
		}
		
		return allList;
	}

	/**
	 * 获取工作面巷道树根节点下的一级节点 
	 * <p>Function: getMineForTreeRoot</p>
	 * <p>Description:</p>
	 * <p>return value:List<Map></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-3-10上午11:20:18 张小飞
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static List<Map> getNodeToProjectInfo(String label){                                                              
		List<Map>  _list = new ArrayList();
		try {
			Map params = new HashMap();
			params.put(TreeConstants.TREE_NODE, label);
			_list = dao.query("ZMCSEngineeringDesign.queryToProjectInfo", params);
		} catch (Exception e) {
			return _list;
		}
		return _list;
	}
	
	/**
	 * 验证工程设计下是否存在工作面\巷道\其他
	 * <p>Function: validateHasChild</p>
	 * <p>Description: </p>
	 * <p>return value:boolean</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-8-24上午08:25:57 严洪浩
	 * </p>
	 *
	 */
	public static boolean validateHasChildren(String designId){                                                              
		try {
			Map<String, String> param = new HashMap<String, String>();
			param.put("fdEngineeringDesignId", designId);
			
			List<?> _list = dao.query("ZMCSWorkingFace.queryInterfaceByDesign", param);
			if(null != _list && _list.size() > 0) {
				return true;
			}
			_list = dao.query("ZMCSRoadWay.queryInterfaceByDesign", param);
			if(null != _list && _list.size() > 0) {
				return true;
			}
			_list = dao.query("ZMCSOtherDesign.queryInterfaceByDesign", param);
			if(null != _list && _list.size() > 0) {
				return true;
			}
		} catch (Exception e) {
			System.out.println("验证工程设计下是否存在工作面，巷道，其他异常：" + e.getMessage());
		}
		return false;
	}
}
